source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-330.rds.xz")
summary(model)
SOM of size 5x5 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 94881 objects.
Mean distance to the closest unit in the map: 0.417.
plot(model, type="changes")
df <- mpr.load_data("datos_mes.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:94881 Length:94881 Min. : 1.000 Min. :-53.0
Class :character Class :character 1st Qu.: 4.000 1st Qu.:148.0
Mode :character Mode :character Median : 6.000 Median :198.0
Mean : 6.497 Mean :200.2
3rd Qu.: 9.000 3rd Qu.:255.0
Max. :12.000 Max. :403.0
tmin precip nevada prof_nieve
Min. :-121.00 Min. : 0.00 Min. :0.000000 Min. : 0.000
1st Qu.: 53.00 1st Qu.: 3.00 1st Qu.:0.000000 1st Qu.: 0.000
Median : 98.00 Median : 10.00 Median :0.000000 Median : 0.000
Mean : 98.86 Mean : 16.25 Mean :0.000295 Mean : 0.467
3rd Qu.: 148.00 3rd Qu.: 22.00 3rd Qu.:0.000000 3rd Qu.: 0.000
Max. : 254.00 Max. :422.00 Max. :6.000000 Max. :1834.000
longitud latitud altitud
Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:38.28 1st Qu.: -5.6417 1st Qu.: 42.0
Median :40.82 Median : -3.4500 Median : 247.0
Mean :39.66 Mean : -3.4350 Mean : 418.5
3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 656.0
Max. :43.57 Max. : 4.2156 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
678 141 2112 3696 3455 801 2301 845 1845 4964 2898 4506 3437 3840 4888 4606
17 18 19 20 21 22 23 24 25
7021 5917 5431 5758 7052 5979 2450 4647 5613
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 5*5;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("fecha_cnt", "tmax", "tmin", "precip")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
fecha_cnt tmax tmin precip
[1,] 0.8288650 0.4752482 0.5407294 -0.1747099
[2,] -0.5027039 0.5313997 0.4277294 -0.5969889
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
tmax fecha_cnt tmin precip
0.9604371 0.9588291 0.9531512 0.9277726
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-42.0 Min. :-108.00 Min. : 41.00
1st Qu.: 8.000 1st Qu.:140.0 1st Qu.: 72.00 1st Qu.: 58.00
Median :10.000 Median :172.0 Median : 99.00 Median : 76.00
Mean : 8.671 Mean :170.6 Mean : 96.87 Mean : 81.19
3rd Qu.:11.000 3rd Qu.:204.0 3rd Qu.: 125.00 3rd Qu.: 94.00
Max. :12.000 Max. :350.0 Max. : 223.00 Max. :422.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.70 1st Qu.: -8.411
Median :0 Median : 0.00 Median :42.33 Median : -4.010
Mean :0 Mean : 1.69 Mean :41.11 Mean : -4.302
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:43.31 3rd Qu.: -1.787
Max. :0 Max. :892.00 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 32.0
Median : 98.0
Mean : 286.4
3rd Qu.: 336.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.:122.0 1st Qu.: 27.00 1st Qu.: 6.00
Median : 4.000 Median :156.0 Median : 58.00 Median :14.00
Mean : 5.868 Mean :151.2 Mean : 54.64 Mean :18.08
3rd Qu.:11.000 3rd Qu.:184.0 3rd Qu.: 84.00 3rd Qu.:27.00
Max. :12.000 Max. :281.0 Max. : 177.00 Max. :93.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:39.49 1st Qu.: -4.8500
Median :0.000000 Median : 0.0000 Median :41.11 Median : -2.7331
Mean :0.000541 Mean : 0.7399 Mean :40.48 Mean : -2.7774
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.33 3rd Qu.: 0.4942
Max. :6.000000 Max. :1834.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 69.0
Median : 427.0
Mean : 527.8
3rd Qu.: 775.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 56.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:236.0 1st Qu.:132.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :265.0 Median :155.0 Median : 5.000 Median :0
Mean : 7.125 Mean :266.8 Mean :156.8 Mean : 8.109 Mean :0
3rd Qu.: 9.000 3rd Qu.:295.0 3rd Qu.:181.0 3rd Qu.:12.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :60.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.18 1st Qu.: -6.0556 1st Qu.: 32.0
Median : 0.00000 Median :39.86 Median : -3.6781 Median : 87.0
Mean : 0.00247 Mean :38.47 Mean : -4.2166 Mean : 287.6
3rd Qu.: 0.00000 3rd Qu.:41.62 3rd Qu.: 0.3664 3rd Qu.: 540.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-42.0 Min. :-108.00 Min. : 41.00
1st Qu.: 8.000 1st Qu.:140.0 1st Qu.: 72.00 1st Qu.: 58.00
Median :10.000 Median :172.0 Median : 99.00 Median : 76.00
Mean : 8.671 Mean :170.6 Mean : 96.87 Mean : 81.19
3rd Qu.:11.000 3rd Qu.:204.0 3rd Qu.: 125.00 3rd Qu.: 94.00
Max. :12.000 Max. :350.0 Max. : 223.00 Max. :422.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.70 1st Qu.: -8.411
Median :0 Median : 0.00 Median :42.33 Median : -4.010
Mean :0 Mean : 1.69 Mean :41.11 Mean : -4.302
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:43.31 3rd Qu.: -1.787
Max. :0 Max. :892.00 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 32.0
Median : 98.0
Mean : 286.4
3rd Qu.: 336.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. :-24.0 Min. :-110.00 Min. : 0.00
1st Qu.:10.00 1st Qu.:119.0 1st Qu.: 32.00 1st Qu.: 5.00
Median :11.00 Median :156.0 Median : 63.00 Median :13.00
Mean :10.99 Mean :152.8 Mean : 59.74 Mean :17.13
3rd Qu.:12.00 3rd Qu.:189.0 3rd Qu.: 91.00 3rd Qu.:26.00
Max. :12.00 Max. :271.0 Max. : 157.00 Max. :88.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :27.92 Min. :-17.7550
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:39.49 1st Qu.: -4.8500
Median :0.0000000 Median : 0.0000 Median :41.11 Median : -2.6544
Mean :0.0004708 Mean : 0.2687 Mean :40.45 Mean : -2.7321
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.24 3rd Qu.: 0.4942
Max. :3.0000000 Max. :382.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 85.0
Median : 513.0
Mean : 572.5
3rd Qu.: 790.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:124.0 1st Qu.: 25.00 1st Qu.: 6.00
Median :3.000 Median :156.0 Median : 55.00 Median :15.00
Mean :2.864 Mean :150.3 Mean : 51.65 Mean :18.64
3rd Qu.:4.000 3rd Qu.:182.0 3rd Qu.: 81.00 3rd Qu.:27.00
Max. :7.000 Max. :281.0 Max. : 177.00 Max. :93.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:39.48 1st Qu.: -5.3456
Median :0.000000 Median : 0.000 Median :41.15 Median : -2.7331
Mean :0.000582 Mean : 1.016 Mean :40.49 Mean : -2.8040
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.36 3rd Qu.: 0.4942
Max. :6.000000 Max. :1834.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 64.0
Median : 370.0
Mean : 501.6
3rd Qu.: 735.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 56.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:236.0 1st Qu.:132.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :265.0 Median :155.0 Median : 5.000 Median :0
Mean : 7.125 Mean :266.8 Mean :156.8 Mean : 8.109 Mean :0
3rd Qu.: 9.000 3rd Qu.:295.0 3rd Qu.:181.0 3rd Qu.:12.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :60.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.18 1st Qu.: -6.0556 1st Qu.: 32.0
Median : 0.00000 Median :39.86 Median : -3.6781 Median : 87.0
Mean : 0.00247 Mean :38.47 Mean : -4.2166 Mean : 287.6
3rd Qu.: 0.00000 3rd Qu.:41.62 3rd Qu.: 0.3664 3rd Qu.: 540.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-42.0 Min. :-108.00 Min. : 41.00
1st Qu.: 8.000 1st Qu.:142.0 1st Qu.: 74.00 1st Qu.: 58.00
Median :10.000 Median :174.0 Median : 100.00 Median : 75.00
Mean : 8.708 Mean :171.9 Mean : 97.71 Mean : 76.92
3rd Qu.:11.000 3rd Qu.:205.0 3rd Qu.: 126.00 3rd Qu.: 91.00
Max. :12.000 Max. :336.0 Max. : 219.00 Max. :149.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.63 1st Qu.: -8.372
Median :0 Median : 0.00 Median :42.34 Median : -4.010
Mean :0 Mean : 1.52 Mean :41.11 Mean : -4.212
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:43.31 3rd Qu.: -1.787
Max. :0 Max. :892.00 Max. :43.57 Max. : 4.216
altitud
Min. : 1.00
1st Qu.: 31.25
Median : 95.00
Mean : 279.32
3rd Qu.: 287.00
Max. :2535.00
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. :142.0 Min. :0
1st Qu.: 3.000 1st Qu.:113.0 1st Qu.: 52.00 1st Qu.:152.0 1st Qu.:0
Median :10.000 Median :131.0 Median : 75.00 Median :167.0 Median :0
Mean : 7.787 Mean :139.5 Mean : 76.75 Mean :183.2 Mean :0
3rd Qu.:11.000 3rd Qu.:154.0 3rd Qu.: 92.00 3rd Qu.:196.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.80 1st Qu.: -8.624 1st Qu.: 68.6
Median : 0.000 Median :42.24 Median : -8.411 Median : 261.0
Mean : 5.752 Mean :41.06 Mean : -6.466 Mean : 455.1
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -3.831 3rd Qu.: 370.0
Max. :607.000 Max. :43.49 Max. : 2.825 Max. :2400.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. :-24.0 Min. :-110.00 Min. : 0.00
1st Qu.:10.00 1st Qu.:119.0 1st Qu.: 32.00 1st Qu.: 5.00
Median :11.00 Median :156.0 Median : 63.00 Median :13.00
Mean :10.99 Mean :152.8 Mean : 59.74 Mean :17.13
3rd Qu.:12.00 3rd Qu.:189.0 3rd Qu.: 91.00 3rd Qu.:26.00
Max. :12.00 Max. :271.0 Max. : 157.00 Max. :88.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :27.92 Min. :-17.7550
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:39.49 1st Qu.: -4.8500
Median :0.0000000 Median : 0.0000 Median :41.11 Median : -2.6544
Mean :0.0004708 Mean : 0.2687 Mean :40.45 Mean : -2.7321
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.24 3rd Qu.: 0.4942
Max. :3.0000000 Max. :382.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 85.0
Median : 513.0
Mean : 572.5
3rd Qu.: 790.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:124.0 1st Qu.: 25.00 1st Qu.: 6.00
Median :3.000 Median :156.0 Median : 55.00 Median :15.00
Mean :2.864 Mean :150.3 Mean : 51.65 Mean :18.64
3rd Qu.:4.000 3rd Qu.:182.0 3rd Qu.: 81.00 3rd Qu.:27.00
Max. :7.000 Max. :281.0 Max. : 177.00 Max. :93.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:39.48 1st Qu.: -5.3456
Median :0.000000 Median : 0.000 Median :41.15 Median : -2.7331
Mean :0.000582 Mean : 1.016 Mean :40.49 Mean : -2.8040
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.36 3rd Qu.: 0.4942
Max. :6.000000 Max. :1834.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 64.0
Median : 370.0
Mean : 501.6
3rd Qu.: 735.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 56.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:236.0 1st Qu.:132.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :265.0 Median :155.0 Median : 5.000 Median :0
Mean : 7.125 Mean :266.8 Mean :156.8 Mean : 8.109 Mean :0
3rd Qu.: 9.000 3rd Qu.:295.0 3rd Qu.:181.0 3rd Qu.:12.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :60.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.18 1st Qu.: -6.0556 1st Qu.: 32.0
Median : 0.00000 Median :39.86 Median : -3.6781 Median : 87.0
Mean : 0.00247 Mean :38.47 Mean : -4.2166 Mean : 287.6
3rd Qu.: 0.00000 3rd Qu.:41.62 3rd Qu.: 0.3664 3rd Qu.: 540.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-42.0 Min. :-108.00 Min. : 73.00 Min. :0
1st Qu.:1.000 1st Qu.:109.0 1st Qu.: 38.25 1st Qu.: 81.00 1st Qu.:0
Median :2.000 Median :127.0 Median : 59.00 Median : 90.00 Median :0
Mean :2.445 Mean :126.5 Mean : 57.15 Mean : 94.87 Mean :0
3rd Qu.:4.000 3rd Qu.:152.0 3rd Qu.: 80.00 3rd Qu.:104.00 3rd Qu.:0
Max. :6.000 Max. :239.0 Max. : 170.00 Max. :149.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.92 Min. :-17.755 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.84 1st Qu.: -8.419 1st Qu.: 42.0
Median : 0.000 Median :42.44 Median : -5.645 Median : 251.0
Mean : 6.524 Mean :41.50 Mean : -5.291 Mean : 439.6
3rd Qu.: 0.000 3rd Qu.:43.30 3rd Qu.: -2.039 3rd Qu.: 370.0
Max. :892.000 Max. :43.57 Max. : 3.182 Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. :142.0 Min. :0
1st Qu.: 3.000 1st Qu.:113.0 1st Qu.: 52.00 1st Qu.:152.0 1st Qu.:0
Median :10.000 Median :131.0 Median : 75.00 Median :167.0 Median :0
Mean : 7.787 Mean :139.5 Mean : 76.75 Mean :183.2 Mean :0
3rd Qu.:11.000 3rd Qu.:154.0 3rd Qu.: 92.00 3rd Qu.:196.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.80 1st Qu.: -8.624 1st Qu.: 68.6
Median : 0.000 Median :42.24 Median : -8.411 Median : 261.0
Mean : 5.752 Mean :41.06 Mean : -6.466 Mean : 455.1
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -3.831 3rd Qu.: 370.0
Max. :607.000 Max. :43.49 Max. : 2.825 Max. :2400.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. :-24.0 Min. :-110.00 Min. : 0.00
1st Qu.:10.00 1st Qu.:119.0 1st Qu.: 32.00 1st Qu.: 5.00
Median :11.00 Median :156.0 Median : 63.00 Median :13.00
Mean :10.99 Mean :152.8 Mean : 59.74 Mean :17.13
3rd Qu.:12.00 3rd Qu.:189.0 3rd Qu.: 91.00 3rd Qu.:26.00
Max. :12.00 Max. :271.0 Max. : 157.00 Max. :88.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :27.92 Min. :-17.7550
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:39.49 1st Qu.: -4.8500
Median :0.0000000 Median : 0.0000 Median :41.11 Median : -2.6544
Mean :0.0004708 Mean : 0.2687 Mean :40.45 Mean : -2.7321
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.24 3rd Qu.: 0.4942
Max. :3.0000000 Max. :382.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 85.0
Median : 513.0
Mean : 572.5
3rd Qu.: 790.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:124.0 1st Qu.: 25.00 1st Qu.: 6.00
Median :3.000 Median :156.0 Median : 55.00 Median :15.00
Mean :2.864 Mean :150.3 Mean : 51.65 Mean :18.64
3rd Qu.:4.000 3rd Qu.:182.0 3rd Qu.: 81.00 3rd Qu.:27.00
Max. :7.000 Max. :281.0 Max. : 177.00 Max. :93.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:39.48 1st Qu.: -5.3456
Median :0.000000 Median : 0.000 Median :41.15 Median : -2.7331
Mean :0.000582 Mean : 1.016 Mean :40.49 Mean : -2.8040
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.36 3rd Qu.: 0.4942
Max. :6.000000 Max. :1834.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 64.0
Median : 370.0
Mean : 501.6
3rd Qu.: 735.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 4.00 Min. : 2.0 Min. :-53.0 Min. : 41.00 Min. :0
1st Qu.:10.00 1st Qu.:155.0 1st Qu.: 86.0 1st Qu.: 55.00 1st Qu.:0
Median :10.00 Median :184.5 Median :109.0 Median : 66.00 Median :0
Mean :10.29 Mean :183.3 Mean :107.9 Mean : 72.39 Mean :0
3rd Qu.:11.00 3rd Qu.:213.0 3rd Qu.:132.0 3rd Qu.: 85.00 3rd Qu.:0
Max. :12.00 Max. :336.0 Max. :219.0 Max. :144.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.85 1st Qu.: -6.949 1st Qu.: 27.0
Median : 0.0000 Median :42.27 Median : -3.831 Median : 87.0
Mean : 0.2584 Mean :41.02 Mean : -3.940 Mean : 238.9
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -0.558 3rd Qu.: 261.0
Max. :114.0000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 56.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:236.0 1st Qu.:132.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :265.0 Median :155.0 Median : 5.000 Median :0
Mean : 7.125 Mean :266.8 Mean :156.8 Mean : 8.109 Mean :0
3rd Qu.: 9.000 3rd Qu.:295.0 3rd Qu.:181.0 3rd Qu.:12.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :60.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.18 1st Qu.: -6.0556 1st Qu.: 32.0
Median : 0.00000 Median :39.86 Median : -3.6781 Median : 87.0
Mean : 0.00247 Mean :38.47 Mean : -4.2166 Mean : 287.6
3rd Qu.: 0.00000 3rd Qu.:41.62 3rd Qu.: 0.3664 3rd Qu.: 540.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-42.0 Min. :-108.00 Min. : 73.00 Min. :0
1st Qu.:1.000 1st Qu.:109.0 1st Qu.: 38.25 1st Qu.: 81.00 1st Qu.:0
Median :2.000 Median :127.0 Median : 59.00 Median : 90.00 Median :0
Mean :2.445 Mean :126.5 Mean : 57.15 Mean : 94.87 Mean :0
3rd Qu.:4.000 3rd Qu.:152.0 3rd Qu.: 80.00 3rd Qu.:104.00 3rd Qu.:0
Max. :6.000 Max. :239.0 Max. : 170.00 Max. :149.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.92 Min. :-17.755 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.84 1st Qu.: -8.419 1st Qu.: 42.0
Median : 0.000 Median :42.44 Median : -5.645 Median : 251.0
Mean : 6.524 Mean :41.50 Mean : -5.291 Mean : 439.6
3rd Qu.: 0.000 3rd Qu.:43.30 3rd Qu.: -2.039 3rd Qu.: 370.0
Max. :892.000 Max. :43.57 Max. : 3.182 Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. :142.0 Min. :0
1st Qu.: 3.000 1st Qu.:113.0 1st Qu.: 52.00 1st Qu.:152.0 1st Qu.:0
Median :10.000 Median :131.0 Median : 75.00 Median :167.0 Median :0
Mean : 7.787 Mean :139.5 Mean : 76.75 Mean :183.2 Mean :0
3rd Qu.:11.000 3rd Qu.:154.0 3rd Qu.: 92.00 3rd Qu.:196.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.80 1st Qu.: -8.624 1st Qu.: 68.6
Median : 0.000 Median :42.24 Median : -8.411 Median : 261.0
Mean : 5.752 Mean :41.06 Mean : -6.466 Mean : 455.1
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -3.831 3rd Qu.: 370.0
Max. :607.000 Max. :43.49 Max. : 2.825 Max. :2400.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. :-24.0 Min. :-110.00 Min. : 0.00
1st Qu.:10.00 1st Qu.:119.0 1st Qu.: 32.00 1st Qu.: 5.00
Median :11.00 Median :156.0 Median : 63.00 Median :13.00
Mean :10.99 Mean :152.8 Mean : 59.74 Mean :17.13
3rd Qu.:12.00 3rd Qu.:189.0 3rd Qu.: 91.00 3rd Qu.:26.00
Max. :12.00 Max. :271.0 Max. : 157.00 Max. :88.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :27.92 Min. :-17.7550
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:39.49 1st Qu.: -4.8500
Median :0.0000000 Median : 0.0000 Median :41.11 Median : -2.6544
Mean :0.0004708 Mean : 0.2687 Mean :40.45 Mean : -2.7321
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.24 3rd Qu.: 0.4942
Max. :3.0000000 Max. :382.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 85.0
Median : 513.0
Mean : 572.5
3rd Qu.: 790.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-53.00 Min. :-121.00 Min. : 1 Min. :0
1st Qu.:1.000 1st Qu.: 5.00 1st Qu.: -56.00 1st Qu.:28 1st Qu.:0
Median :2.000 Median : 28.00 Median : -38.00 Median :39 Median :0
Mean :2.498 Mean : 25.85 Mean : -40.17 Mean :41 Mean :0
3rd Qu.:3.000 3rd Qu.: 49.00 3rd Qu.: -20.00 3rd Qu.:52 3rd Qu.:0
Max. :6.000 Max. : 98.00 Max. : 16.00 Max. :93 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00 Min. :28.31 Min. :-16.4992 Min. : 42
1st Qu.: 0.00 1st Qu.:40.84 1st Qu.: -4.0103 1st Qu.:1894
Median : 0.00 Median :42.47 Median : 0.8842 Median :2230
Mean : 29.99 Mean :41.66 Mean : -0.7733 Mean :2034
3rd Qu.: 0.00 3rd Qu.:42.64 3rd Qu.: 1.3656 3rd Qu.:2371
Max. :1834.00 Max. :43.46 Max. : 2.4803 Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. : 63.0 Min. :-11.00 Min. :14.0 Min. :0
1st Qu.:3.000 1st Qu.:148.0 1st Qu.: 61.00 1st Qu.:24.0 1st Qu.:0
Median :4.000 Median :168.0 Median : 79.00 Median :30.0 Median :0
Mean :3.625 Mean :170.7 Mean : 80.57 Mean :34.3 Mean :0
3rd Qu.:5.000 3rd Qu.:192.0 3rd Qu.: 99.00 3rd Qu.:42.0 3rd Qu.:0
Max. :7.000 Max. :281.0 Max. :177.00 Max. :78.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.56 1st Qu.: -5.8792 1st Qu.: 42.0
Median : 0.00000 Median :41.91 Median : -3.7892 Median : 143.0
Mean : 0.06697 Mean :40.87 Mean : -3.4123 Mean : 343.8
3rd Qu.: 0.00000 3rd Qu.:43.30 3rd Qu.: 0.3264 3rd Qu.: 521.0
Max. :45.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 4.00 Min. : 2.0 Min. :-53.0 Min. : 41.00 Min. :0
1st Qu.:10.00 1st Qu.:155.0 1st Qu.: 86.0 1st Qu.: 55.00 1st Qu.:0
Median :10.00 Median :184.5 Median :109.0 Median : 66.00 Median :0
Mean :10.29 Mean :183.3 Mean :107.9 Mean : 72.39 Mean :0
3rd Qu.:11.00 3rd Qu.:213.0 3rd Qu.:132.0 3rd Qu.: 85.00 3rd Qu.:0
Max. :12.00 Max. :336.0 Max. :219.0 Max. :144.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.85 1st Qu.: -6.949 1st Qu.: 27.0
Median : 0.0000 Median :42.27 Median : -3.831 Median : 87.0
Mean : 0.2584 Mean :41.02 Mean : -3.940 Mean : 238.9
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -0.558 3rd Qu.: 261.0
Max. :114.0000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-17.0 Min. :-89.00 Min. : 0.00
1st Qu.:1.000 1st Qu.:114.0 1st Qu.: 16.00 1st Qu.: 4.00
Median :2.000 Median :149.0 Median : 41.00 Median : 9.00
Mean :2.517 Mean :145.3 Mean : 41.33 Mean :10.38
3rd Qu.:3.000 3rd Qu.:177.0 3rd Qu.: 69.00 3rd Qu.:15.00
Max. :7.000 Max. :254.0 Max. :124.00 Max. :50.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :28.31 Min. :-17.7550
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:39.47 1st Qu.: -4.6800
Median :0.000000 Median : 0.0000 Median :40.95 Median : -2.3567
Mean :0.000881 Mean : 0.3909 Mean :40.27 Mean : -2.5906
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:41.84 3rd Qu.: 0.4942
Max. :6.000000 Max. :503.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 81.0
Median : 510.0
Mean : 519.6
3rd Qu.: 779.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 56.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:236.0 1st Qu.:132.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :265.0 Median :155.0 Median : 5.000 Median :0
Mean : 7.125 Mean :266.8 Mean :156.8 Mean : 8.109 Mean :0
3rd Qu.: 9.000 3rd Qu.:295.0 3rd Qu.:181.0 3rd Qu.:12.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :60.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.18 1st Qu.: -6.0556 1st Qu.: 32.0
Median : 0.00000 Median :39.86 Median : -3.6781 Median : 87.0
Mean : 0.00247 Mean :38.47 Mean : -4.2166 Mean : 287.6
3rd Qu.: 0.00000 3rd Qu.:41.62 3rd Qu.: 0.3664 3rd Qu.: 540.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-42.0 Min. :-108.00 Min. : 73.00 Min. :0
1st Qu.:1.000 1st Qu.:109.0 1st Qu.: 38.25 1st Qu.: 81.00 1st Qu.:0
Median :2.000 Median :127.0 Median : 59.00 Median : 90.00 Median :0
Mean :2.445 Mean :126.5 Mean : 57.15 Mean : 94.87 Mean :0
3rd Qu.:4.000 3rd Qu.:152.0 3rd Qu.: 80.00 3rd Qu.:104.00 3rd Qu.:0
Max. :6.000 Max. :239.0 Max. : 170.00 Max. :149.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.92 Min. :-17.755 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.84 1st Qu.: -8.419 1st Qu.: 42.0
Median : 0.000 Median :42.44 Median : -5.645 Median : 251.0
Mean : 6.524 Mean :41.50 Mean : -5.291 Mean : 439.6
3rd Qu.: 0.000 3rd Qu.:43.30 3rd Qu.: -2.039 3rd Qu.: 370.0
Max. :892.000 Max. :43.57 Max. : 3.182 Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. :142.0 Min. :0
1st Qu.: 3.000 1st Qu.:113.0 1st Qu.: 52.00 1st Qu.:152.0 1st Qu.:0
Median :10.000 Median :131.0 Median : 75.00 Median :167.0 Median :0
Mean : 7.787 Mean :139.5 Mean : 76.75 Mean :183.2 Mean :0
3rd Qu.:11.000 3rd Qu.:154.0 3rd Qu.: 92.00 3rd Qu.:196.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.80 1st Qu.: -8.624 1st Qu.: 68.6
Median : 0.000 Median :42.24 Median : -8.411 Median : 261.0
Mean : 5.752 Mean :41.06 Mean : -6.466 Mean : 455.1
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -3.831 3rd Qu.: 370.0
Max. :607.000 Max. :43.49 Max. : 2.825 Max. :2400.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. :-24.00 Min. :-110.00 Min. : 0.00
1st Qu.:11.00 1st Qu.: 84.00 1st Qu.: -2.00 1st Qu.: 7.00
Median :12.00 Median :101.00 Median : 17.00 Median :18.00
Mean :11.59 Mean : 97.71 Mean : 16.41 Mean :23.13
3rd Qu.:12.00 3rd Qu.:116.00 3rd Qu.: 35.00 3rd Qu.:37.00
Max. :12.00 Max. :179.00 Max. : 89.00 Max. :88.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:40.70 1st Qu.: -4.6992
Median :0.000000 Median : 0.0000 Median :41.67 Median : -3.1742
Mean :0.001617 Mean : 0.8346 Mean :41.18 Mean : -2.9220
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.47 3rd Qu.: 0.3264
Max. :3.000000 Max. :382.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 510.0
Median : 704.0
Mean : 869.7
3rd Qu.:1004.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 7.00 Min. : 95.0 Min. :-20.00 Min. : 0.00 Min. :0
1st Qu.:10.00 1st Qu.:151.0 1st Qu.: 57.00 1st Qu.: 5.00 1st Qu.:0
Median :11.00 Median :175.0 Median : 79.00 Median :13.00 Median :0
Mean :10.75 Mean :175.4 Mean : 77.55 Mean :14.66 Mean :0
3rd Qu.:11.00 3rd Qu.:199.0 3rd Qu.: 99.00 3rd Qu.:22.00 3rd Qu.:0
Max. :12.00 Max. :271.0 Max. :157.00 Max. :49.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.92 Min. :-17.7550 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:38.95 1st Qu.: -4.8500 1st Qu.: 47.0
Median : 0.00000 Median :40.93 Median : -2.4831 Median : 287.0
Mean : 0.03624 Mean :40.15 Mean : -2.6541 Mean : 450.4
3rd Qu.: 0.00000 3rd Qu.:41.98 3rd Qu.: 0.5706 3rd Qu.: 674.0
Max. :59.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-53.00 Min. :-121.00 Min. : 1 Min. :0
1st Qu.:1.000 1st Qu.: 5.00 1st Qu.: -56.00 1st Qu.:28 1st Qu.:0
Median :2.000 Median : 28.00 Median : -38.00 Median :39 Median :0
Mean :2.498 Mean : 25.85 Mean : -40.17 Mean :41 Mean :0
3rd Qu.:3.000 3rd Qu.: 49.00 3rd Qu.: -20.00 3rd Qu.:52 3rd Qu.:0
Max. :6.000 Max. : 98.00 Max. : 16.00 Max. :93 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00 Min. :28.31 Min. :-16.4992 Min. : 42
1st Qu.: 0.00 1st Qu.:40.84 1st Qu.: -4.0103 1st Qu.:1894
Median : 0.00 Median :42.47 Median : 0.8842 Median :2230
Mean : 29.99 Mean :41.66 Mean : -0.7733 Mean :2034
3rd Qu.: 0.00 3rd Qu.:42.64 3rd Qu.: 1.3656 3rd Qu.:2371
Max. :1834.00 Max. :43.46 Max. : 2.4803 Max. :2535
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. : 63.0 Min. :-11.00 Min. :14.0 Min. :0
1st Qu.:3.000 1st Qu.:148.0 1st Qu.: 61.00 1st Qu.:24.0 1st Qu.:0
Median :4.000 Median :168.0 Median : 79.00 Median :30.0 Median :0
Mean :3.625 Mean :170.7 Mean : 80.57 Mean :34.3 Mean :0
3rd Qu.:5.000 3rd Qu.:192.0 3rd Qu.: 99.00 3rd Qu.:42.0 3rd Qu.:0
Max. :7.000 Max. :281.0 Max. :177.00 Max. :78.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.56 1st Qu.: -5.8792 1st Qu.: 42.0
Median : 0.00000 Median :41.91 Median : -3.7892 Median : 143.0
Mean : 0.06697 Mean :40.87 Mean : -3.4123 Mean : 343.8
3rd Qu.: 0.00000 3rd Qu.:43.30 3rd Qu.: 0.3264 3rd Qu.: 521.0
Max. :45.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 4.00 Min. : 2.0 Min. :-53.0 Min. : 41.00 Min. :0
1st Qu.:10.00 1st Qu.:155.0 1st Qu.: 86.0 1st Qu.: 55.00 1st Qu.:0
Median :10.00 Median :184.5 Median :109.0 Median : 66.00 Median :0
Mean :10.29 Mean :183.3 Mean :107.9 Mean : 72.39 Mean :0
3rd Qu.:11.00 3rd Qu.:213.0 3rd Qu.:132.0 3rd Qu.: 85.00 3rd Qu.:0
Max. :12.00 Max. :336.0 Max. :219.0 Max. :144.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.85 1st Qu.: -6.949 1st Qu.: 27.0
Median : 0.0000 Median :42.27 Median : -3.831 Median : 87.0
Mean : 0.2584 Mean :41.02 Mean : -3.940 Mean : 238.9
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -0.558 3rd Qu.: 261.0
Max. :114.0000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-17.0 Min. :-89.00 Min. : 0.00
1st Qu.:1.000 1st Qu.:114.0 1st Qu.: 16.00 1st Qu.: 4.00
Median :2.000 Median :149.0 Median : 41.00 Median : 9.00
Mean :2.517 Mean :145.3 Mean : 41.33 Mean :10.38
3rd Qu.:3.000 3rd Qu.:177.0 3rd Qu.: 69.00 3rd Qu.:15.00
Max. :7.000 Max. :254.0 Max. :124.00 Max. :50.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :28.31 Min. :-17.7550
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:39.47 1st Qu.: -4.6800
Median :0.000000 Median : 0.0000 Median :40.95 Median : -2.3567
Mean :0.000881 Mean : 0.3909 Mean :40.27 Mean : -2.5906
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:41.84 3rd Qu.: 0.4942
Max. :6.000000 Max. :503.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 81.0
Median : 510.0
Mean : 519.6
3rd Qu.: 779.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip nevada
Min. : 4.000 Min. :181.0 Min. : 70.0 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:251.0 1st Qu.:144.0 1st Qu.: 0.000 1st Qu.:0
Median : 8.000 Median :277.0 Median :165.0 Median : 4.000 Median :0
Mean : 7.791 Mean :277.7 Mean :166.1 Mean : 7.984 Mean :0
3rd Qu.: 9.000 3rd Qu.:302.0 3rd Qu.:188.0 3rd Qu.:12.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :60.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.26 1st Qu.: -5.8728 1st Qu.: 27.1
Median : 0.00000 Median :39.88 Median : -3.5556 Median : 87.0
Mean : 0.00298 Mean :38.64 Mean : -3.8958 Mean : 279.2
3rd Qu.: 0.00000 3rd Qu.:41.61 3rd Qu.: 0.4914 3rd Qu.: 540.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. : 87.0 Min. : 56.0 Min. : 0.000 Min. :0
1st Qu.:4.000 1st Qu.:210.0 1st Qu.:107.0 1st Qu.: 3.000 1st Qu.:0
Median :5.000 Median :225.0 Median :122.0 Median : 8.000 Median :0
Mean :4.659 Mean :226.3 Mean :122.3 Mean : 8.575 Mean :0
3rd Qu.:6.000 3rd Qu.:244.0 3rd Qu.:137.0 3rd Qu.:14.000 3rd Qu.:0
Max. :8.000 Max. :300.0 Max. :185.0 Max. :30.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.:0.0000000 1st Qu.:36.50 1st Qu.: -6.949 1st Qu.: 32.0
Median :0.0000000 Median :39.56 Median : -4.023 Median : 87.0
Mean :0.0005932 Mean :37.85 Mean : -5.404 Mean : 318.9
3rd Qu.:0.0000000 3rd Qu.:41.66 3rd Qu.: -1.169 3rd Qu.: 567.0
Max. :3.0000000 Max. :43.57 Max. : 4.216 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)